package com.shujia.mr.mc1;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class WordCountDemo {
    public static void main(String[] args) throws Exception{
        //创建hadoop配置文件对象
        Configuration con = new Configuration();
        //创建Job作业对象
        Job job = Job.getInstance(con);
        job.setJobName("红细胞特别行动小组");
        //设置reduce的个数
//        job.setNumReduceTasks(4);

        //设置主类名
        job.setJarByClass(WordCountDemo.class);
        //设置Map类
        job.setMapperClass(MyMapper.class);
        //设置reduce类
        job.setReducerClass(Myreduce.class);
        //设置Map任务输出的键和值类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(LongWritable.class);
        //设置reduce任务输出的键和值的类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);
        //设置文件输入路径
        //hadoop jar xxx.jar MR的主类名 输入文件的路径 输出文件的路径
        FileInputFormat.addInputPath(job,new Path(args[0]));
        //设置文件输出的路径
        FileOutputFormat.setOutputPath(job,new Path(args[1]));
        //提交作业到yarn上面执行，由yarn进行分配资源
        boolean flag = job.waitForCompletion(true);
        //flag标志执行的成功与否
        if (flag) {
            System.out.println("29期WordCount如门程序执行成功============");
        }else {
            System.out.println("运行失败");
        }
    }
}
